import { Space, Table, Tag } from "antd";
import React from "react";

const { Column, ColumnGroup } = Table;
import Manage from "./index";
export default function Student({students}:any) {
    return (
        <Manage>
            <h2>学生管理</h2>
            <Table dataSource={students}>
                <Column title="姓名" dataIndex="name" key="name" />
                <Column title="性别" dataIndex="gender" key="gender" />

                <Column title="年龄" dataIndex="age" key="age" />
                <Column
                    title="Action"
                    key="action"
                    render={(_: any, record: any) => (
                        <Space size="middle">
                            <a>Update</a>
                            <a>Delete</a>
                        </Space>
                    )}
                />
            </Table>
        </Manage>
    );
}

// export async function getStaticProps(context: any) {
//     const res = await fetch(`http://localhost:8080/students`)
//     const data = await res.json()
//     return {
//         props: {
//             students:data.rows
//         }, // will be passed to the page component as props
//     };
// }

export async function getServerSideProps(context:any) {
    const res = await fetch(`http://localhost:8080/students`)
    const data = await res.json()
    return {
      props: {
        students:data.rows
      }, // will be passed to the page component as props
    }
  }
